angular.module('mamApp').controller('specialTagsModalController', ['$scope', '$state', '$uibModal', 'ImsDialog', 'TagsManager', '$filter', '$uibModalInstance', 'data','BaseValidations',
    function ($scope, $state, $uibModal, ImsDialog, TagsManager, $filter, $uibModalInstance, data,BaseValidations) {

        $scope.specialDimension = data.specialDimension;
        $scope.formData = data.formData;
        if (!$scope.formData.specialId) {
            $scope.formData.status = 2;
        }
        $scope.table = JSON.parse(localStorage.getItem("codeTable"));

        $scope.initData = {
            "status": ["4", "2"]
        };
        $scope.BaseValidations = BaseValidations;
        //新建确定(标签名称是否存在后台判断)
        $scope.okCreate = function () {
            $scope.formData.specialName= $scope.formData.specialName.replace(/，|；|;|、|\s/g,",");
            TagsManager.specialTagAdd($scope.formData).then(function (result) {
                if (result.data.c == "s") {
                    $uibModalInstance.close("ok");
                } else {
                    $scope.nameCheck = true;
                    $scope.message=result.data.i;
                }
            });
        };

        //编辑确定(标签名称是否存在后台判断)
        $scope.okEdit = function () {
            $scope.formData.specialName= $scope.formData.specialName.replace(/，|；|;|、|\s/g,",");
            TagsManager.specialTagEdit($scope.formData.specialId, $scope.formData).then(function (result) {
                if (result.data.c == "s") {
                    $uibModalInstance.close("ok");
                } else {
                    $scope.nameCheck = true;
                    $scope.message=result.data.i;
                    //$uibModalInstance.close("error");
                }
            });
        };

        $scope.cancel = function () {
            $uibModalInstance.close("cancel");
        };

    }]);

